package bloggo

type R struct {
	Flag    bool        `json:"flag"`
	Code    int32       `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
	Request string      `json:"request"`
}

// Ok 成功
func Ok() *R {
	return &R{
		Flag:    true,
		Code:    20000,
		Message: "操作成功",
	}
}

// Fail 失败
func Fail() *R {
	return &R{
		Flag:    false,
		Code:    51000,
		Message: "操作失败",
	}
}

// NoPermission 无权限
func NoPermission() *R {
	return &R{
		Code:    61000,
		Message: "无操作权限",
	}
}

func OkData(data interface{}) *R {
	ok := Ok()
	ok.Data = data
	return ok
}

func OkMessage(data interface{}, message string) *R {
	ok := Ok()
	ok.Data = data
	ok.Message = message
	return ok
}

func FailMessage(message string) *R {
	fail := Fail()
	fail.Message = message
	return fail
}

func UnknownErr() *R {
	fail := Fail()
	fail.Message = "未知错误"
	return fail
}

func NoToken() *R {
	fail := NoPermission()
	fail.Message = "未携带访问令牌,无权限访问"
	return fail
}

func TokenExpired() *R {
	fail := NoPermission()
	fail.Message = "访问令牌已超时,无权限访问"
	return fail
}

func TokenNotValidYet() *R {
	fail := NoPermission()
	fail.Message = "令牌尚未生效,无权限访问"
	return fail
}

func TokenMalformed() *R {
	fail := NoPermission()
	fail.Message = "令牌格式错误,无权限访问"
	return fail
}

func TokenInvalid() *R {
	fail := NoPermission()
	fail.Message = "令牌无效,无权限访问"
	return fail
}
